﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Marmat.Foundation;
using Microsoft.Extensions.DependencyInjection;

namespace Marmat.Template.WinForm
{
    /// <summary>
    /// 注册默认的模块
    /// </summary>
    public static class DefaultInjection
    {
        /// <summary>
        /// 初始化框架内置模板
        /// </summary>
        /// <param name="services"></param>
        public static void AddWinFormTemplate(this IServiceCollection services)
        {
            services.AddScoped<Marmat.Foundation.IUserProvider, Marmat.Foundation.UserProvider>();//登录用户的提供服务。
            services.AddScoped<Marmat.Foundation.IMainForm, Marmat.Template.WinForm.MainForm>();//主窗体
            services.AddTransient<Marmat.Foundation.ILoginForm, Marmat.Template.WinForm.DefaultLoginForm>();//登录窗体
            services.AddTransient<Marmat.Foundation.IViewForm, Marmat.Template.WinForm.ViewForm>();//视图窗体
            services.AddTransient<Marmat.Foundation.IEditForm, Marmat.Template.WinForm.EditForm>();//编辑窗体
            services.AddTransient<Marmat.Foundation.ISearchControl, Marmat.Template.WinForm.SearchControl>();//搜索控件
            services.AddTransient<Marmat.Foundation.IMeunManagement, MeunManagement>();//菜单管理

            #region 记录选择窗体
            services.AddTransient<ISelectionRecordForm, SelectionRecordForm>();
            services.AddTransient<ISelectionRecordPaginationForm, SelectionRecordPaginationForm>();
            services.AddTransient<ISelectionRecordMultiForm, SelectionRecordMultiForm>();
            services.AddTransient<ISelectionRecordMultiPaginationForm, SelectionRecordMultiPaginationForm>();
            services.AddTransient(typeof(ISelectionRecordForm<>), typeof(SelectionRecordForm<>));
            services.AddTransient(typeof(ISelectionRecordPaginationForm<>), typeof(SelectionRecordPaginationForm<>));
            services.AddTransient(typeof(ISelectionRecordMultiForm<>), typeof(SelectionRecordMultiForm<>));
            services.AddTransient(typeof(ISelectionRecordMultiPaginationForm<>), typeof(SelectionRecordMultiPaginationForm<>));
            services.AddTransient(typeof(ISelectionRecordForm<,>), typeof(SelectionRecordForm<,>));
            services.AddTransient(typeof(ISelectionRecordPaginationForm<,>), typeof(SelectionRecordPaginationForm<,>));
            services.AddTransient(typeof(ISelectionRecordMultiForm<,>), typeof(SelectionRecordMultiForm<,>));
            services.AddTransient(typeof(ISelectionRecordMultiPaginationForm<,>), typeof(SelectionRecordMultiPaginationForm<,>));
            #endregion

            //services.AddTransient<IReLogin, ReLogin>();//重新登录的实现。
            services.AddTransient<ICache, CacheService>();//缓存的实现。
            services.AddTransient<IExportForm, ExportForm>();
            services.AddTransient<IChangePasswordForm, ChangePasswordForm>();
            services.AddScoped<INotificationBus, MemoryNotificationBus>();

            services.AddTransient<Marmat.Foundation.IColumnViewConfiguration, ColumnViewConfiguration>();
        }

        /// <summary>
        /// 注册单据模块
        /// </summary>
        /// <param name="services"></param>
        public static void RegisterModel<TModel>(this IServiceCollection services) where TModel : class, IDocumentManagement
        {
            services.AddScoped<Marmat.Foundation.IMenuItemBuilder, TModel>();//登录用户的提供服务。           
        }

        /// <summary>
        /// 启用开发模式
        /// </summary>
        /// <param name="services"></param>
        public static void UseDeveloper(this IServiceCollection services)
        {
        }
    }
}
